package com.example.servletdemo.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//@WebFilter(filterName = "test2Filter",urlPatterns = "/user/*",dispatcherTypes = DispatcherType.REQUEST)
//@WebFilter(filterName = "test2Filter",urlPatterns = "/index.jsp",dispatcherTypes = DispatcherType.REQUEST)
//@WebFilter(filterName = "test2Filter",urlPatterns = "/index.jsp",dispatcherTypes = {DispatcherType.REQUEST,DispatcherType.FORWARD})
public class Test2Filter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("TestFilter2:init");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletResponse response= (HttpServletResponse) servletResponse;

        System.out.println("TestFilter2:doFilter");
        filterChain.doFilter(servletRequest,servletResponse);
//        response.sendRedirect("/login.jsp");
//        response.setHeader("a","123");
    }

    @Override
    public void destroy() {
        System.out.println("TestFilter2:destroy");
    }
}
